package com.liuyucheng.idea_springboot.controller;

import com.liuyucheng.idea_springboot.bean.Result;
import com.liuyucheng.idea_springboot.bean.VueStudent;
import com.liuyucheng.idea_springboot.dao.IndexMapper;
import com.liuyucheng.idea_springboot.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * vue学习专用控制层
 */
@RestController
@RequestMapping("/vueStudy")
public class VueStudyController {

    //http://localhost:9000/SpringbootDemo/vueStudy/students
    @Resource
    private IndexMapper indexMapper;

    @Autowired
    private RedisUtil redisUtil;

    /**
     * 获取下拉框信息
     */
    @GetMapping("/students")
    @ResponseBody
    public List<VueStudent> students(HttpServletRequest request) {
        VueStudent student1 = new VueStudent().setId("001").setName("杜兰特").setAge(32);
        VueStudent student2 = new VueStudent().setId("002").setName("艾弗森").setAge(33);
        VueStudent student3 = new VueStudent().setId("003").setName("纳什").setAge(21);
        List<VueStudent> list = new ArrayList<>();
        list.add(student1);
        list.add(student2);
        list.add(student3);
        return list;
    }

    /**
     * 测试容器编排
     * @param request 请求
     * @return 结果
     */
    @GetMapping("/dockerCompose")
    @ResponseBody
    public Result<?> dockerCompose(HttpServletRequest request) {
        List<Map<String, Object>> maps = indexMapper.selectAll();
        redisUtil.set("dockerCompose",new Date().toString());
        return Result.data(maps);
    }
}
